package homework;
/**
 * N进制转换成int
 * @author Alex
 *
 */
public class DE7 {

    public static void main(String[] args) {
//        String num="16";
//        int n=Integer.parseInt(num,16);
//        System.out.println(n);
    }

    public static int paseInt(String num, int base) {
        //未考虑负数
        int sum = 0;
        int weight = 1;
        for (int i = num.length() - 1; i >= 0; i--) {
            char ch = num.charAt(i);
            int n = ch - '0';
            if (!(n>=0&&n<base)) {
                throw new NumberFormatException(num);
            }
            sum += n * weight;
            weight *= base;
        }
        return sum;
    }

}
